﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>条件设置</title>
    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../Admin.js" type="text/javascript"></script>

    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <base target="_self" />
    <style type="text/css">
        caption {
            text-align: left;
            font-family: 'Microsoft YaHei';
            font-weight: bolder;
            border-bottom: none;
            margin-bottom: 10px;
        }

        #Btn_New {
            border: 1px solid #031f5d;
            background-color: #fff;
            color: #031f5d;
            background-image: url(../../Img/Btn/New.png)!important;
            background-size: 13px 13px !important;
            background-position: 1px 6px !important;
        }
    </style>
    <script type="text/javascript">
        //获得变量.

        //流程编号.
        var flowNo = GetQueryString("FK_Flow");

        //作用的节点.
        var nodeID = GetQueryString("FK_Node");

        //到达的节点，对方向条件有效.
        var toNodeID = GetQueryString("ToNodeID");
        if (toNodeID == null)
            toNodeID = nodeID;

        //条件类型 @0=节点完成条件, 1=流程完成条件, 2=方向条件, 3=启动子流程
        var condType = GetQueryString("CondType");
        if (condType == null || condType == '')
            condType = 2;

        var dir = null;
        //初始化页面函数.....
        $(function () {

            $("#table").html("");
            if (condType == null || condType == undefined)
                condType = 2; //默认为方向条件.

            //查询出来所有的条件方向条件.
            var conds = new Entities("BP.WF.Template.Conds");
            conds.Retrieve("FK_Node", nodeID, "ToNodeID", toNodeID,
                "CondType", condType, "Idx");

            html = "<table class='table table-striped table-bordered table-hover table-condensed' style='width:98%;'>";

            //输出条件类型.
            if (condType == 0)
                html += "<caption><img style='margin-top:8px;'; src='../../Img/Event.png' />节点完成条件</caption>";

            if (condType == 2) {
                var toNode = new Entity("BP.WF.Node", toNodeID);
                html += "<caption><img style='margin-top:8px;'; src='../../Img/Event.png' />到达节点[<font color=green>" + toNode.NodeID + " " + toNode.Name + "</font>]的方向条件</caption>";
            }

            if (condType == 1)
                html += "<caption><img style='margin-top:8px;'; src='../../Img/Event.png' />流程完成条件</caption>";
            if (condType == 3)
                html += "<caption><img style='margin-top:8px;'; src='../../Img/Event.png' />子流程启动条件</caption>";

            html += "<tr>";
            html += "<th>Idx</th>";
            html += "<th>类型</th>";
            html += "<th>表达式</th>";
            html += "<th>插入运算符</th>";
            html += "<th>移动</th>";
            html += "<th>删除</th>";
            html += "</tr>";
            //循环生成表格.
            var idx = 1;
            for (var i = 0; i < conds.length; i++) {

                var cond = conds[i];

                if (cond.DataFrom == 100)
                    html += "<tr Class=Sum >";
                else
                    html += "<tr >";

                html += "<td class=Idx>" + cond.Idx + "</td>";
                html += "<td>" + ShowType(cond.DataFrom) + "</td>"; //类型
                html += "<td style='width:300px;height:40px;'>";

                if (cond.DataFrom == 100) {
                    html += " " + cond.OperatorValue;
                } else {
                    html += cond.AttrKey + cond.FK_Operator + cond.OperatorValue;

                    if (cond.AttrKey != "")
                        html += "<br>说明：" + cond.AttrName + " " + cond.FK_Operator + " " + "" + cond.OperatorValue;
                }

                html += "</td>";//表达式 "  " " +  + " " + en.OperatorValue;
                html += "<td><a  href=\"javascript:ShowHidden('state" + i + "')\">插入运算符</a></td>";
                html += "<div id='state" + i + "' style='position: absolute; z-index: 10; background-color: white; border: 1px outset black; display: none; color: Gray; left:480px;top:" + ((50 + idx * 50)) + "px; '>";
                html += " <ol>";
                html += " <li><a href=\"javascript:AddCond('(','" + cond.Idx + "')\"> ( 左括号 &nbsp;&nbsp;&nbsp;&nbsp; </a> </li>";
                html += " <li><a href=\"javascript: AddCond(')','" + cond.Idx + "')\"> ) 右括号&nbsp;&nbsp;&nbsp;&nbsp;</a> </li>";
                html += " <li><a href=\"javascript: AddCond('AND','" + cond.Idx + "')\"> AND 并且&nbsp;&nbsp;&nbsp;&nbsp;</a> </li>";
                html += " <li><a href=\"javascript: AddCond('OR','" + cond.Idx + "')\"> OR 或者&nbsp;&nbsp;&nbsp;&nbsp;</a> </li>";
                html += " </ol>";
                html += "</div>";
                html += "<td>";

                html += " - <a class='btn btn-default btn-sm' href=\"javascript:Up('" + cond.MyPK + "')\"><img src='../../Img/Btn/Up.gif' border=0 />上移</a>";
                html += " - <a class='btn btn-default btn-sm' href=\"javascript:Down('" + cond.MyPK + "')\"><img src='../../Img/Btn/Down.gif' border=0 />下移</a>";
                html += "<td>";
                html += "<a  href=\"javascript:DeleteIt('" + cond.MyPK + "')\"><img src='../../Img/Btn/Delete.gif' border=0 />删除</a>";
                html += "</tr>";
                idx++;
            }
            html += "</table>";
            $("#table").html(html);

            //新建运算符按钮的显示和隐藏
            $("#condBtn").hide();

            //   if (dir.CondExpModel == 2) {
            $("#condBtn").show();

            //调用检查条件设置是否正确.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond2020");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("List_DoCheck");

            if (data.indexOf('err@') >= 0)
                $("#checkInfo").html("<font color=red>" + data + "</font>");
            else
                $("#checkInfo").html("<font color=green>" + data + "</font>");
        });

        function ShowType(DataFrom) {
            var res = "";
            switch (DataFrom) {
                case 0: res = "表单字段";
                    break;
                case 1: res = "独立表单";
                    break;
                case 2: res = "按岗位";
                    break;
                case 3: res = "按部门";
                    break;
                case 4: res = "按SQL";
                    break;
                case 5: res = "按SQL模板";
                    break;
                case 6: res = "按参数";
                    break;
                case 7: res = "按URL";
                    break;
                case 8: res = "按WebApi返回值";
                    break;
                case 9: res = "按审核组件立场";
                    break;
                case 100: res = "运算符";
                    break;
            }
            return res;
        }


        //执行删除..
        function DeleteIt(mypk) {
            if (window.confirm('您确定要删除吗？') == false)
                return;
            var en = new Entity("BP.WF.Template.Cond");
            en.SetPKVal(mypk);
            en.Delete();
            window.location.href = window.location.href;
            return;
        }
        function Up(mypk) {
            var en = new Entity("BP.WF.Template.Cond");
            en.SetPKVal(mypk);
            en.Retrieve();
            var data = en.DoMethodReturnString("DoUp2020Cond");
            window.location.href = window.location.href;
            return;
        }
        function Down(mypk) {
            var en = new Entity("BP.WF.Template.Cond");
            en.SetPKVal(mypk);
            en.Retrieve();
            var data = en.DoMethodReturnString("DoDown2020Cond");
            window.location.href = window.location.href;
            return;
        }

        /*隐藏与显示.*/
        function ShowHidden(ctrlID) {

            var ctrl = document.getElementById(ctrlID);

            ctrl.style.display = 'block';

            document.onmouseup = function () {

                ctrl.style.display = "none";
            }
        }

        function NewCond(type) {

            var url = window.location.href;
            url = url.replace('List.htm', type + '.htm');
            window.location.href = url;
        }
        //添加运算符
        function AddCond(condExp, idx) {
            var condIdx = idx - 1;
            var en = new Entity("BP.WF.Template.Cond");
            //生成一个随机数添加到运算符的主键中
            var radomNum = parseInt(Math.random() * 1000) + 1;
            en.SetPKVal(flowNo + "_" + nodeID + "_" + radomNum);
            en.CondType = condType; //条件类型.
            en.DataFrom = 100;  //运算符.
            en.FK_Flow = flowNo;
            en.FK_Node = nodeID;

            en.FK_Operator = condExp; //都赋值，以免用错.
            en.OperatorValue = condExp; //都赋值，以免用错.

            en.ToNodeID = toNodeID;
            en.Idx = condIdx;
            en.Insert();

            //en.DoMethodReturnString("DoDown2020Cond");


            window.location.href = window.location.href;
        }
    </script>

</head>
<body>
    <div style="right:30px; position:absolute; z-index:100; ">
        <input id="Btn_New" type="button" value="新建条件" onclick="ShowHidden('state')" />
        <div id="state" style="position:absolute; z-index:10;background-color:white; border:1px outset black; display: none; color: Gray;left:-120px ">
            <ol>
                <li><a href="javascript:NewCond('CondByFrm');">按表单条件计算</a> </li>
                <li><a href="javascript:NewCond('StandAloneFrm');">按已选择的独立表单条件计算</a> </li>
                <li><a href="javascript:NewCond('CondStation');">按指定操作员的岗位条件</a></li>
                <li><a href="javascript:NewCond('CondDept');">按指定操作员的部门条件</a> </li>
                <li><a href="javascript:NewCond('CondBySQL');">按SQL条件计算</a> </li>
                <li><a href="javascript:NewCond('CondBySQLTemplate');">按SQL模版条件计算</a> </li>
                <li><a href="javascript:NewCond('CondByPara');">按开发者参数计算</a> </li>
                <li><a href="javascript:NewCond('CondByUrl');">按Url条件计算</a> </li>
                <li><a href="javascript:NewCond('CondByWebApi');">按WebApi返回值</a> </li>
                <li><a href="javascript:NewCond('CondByWorkCheck');">按审核组件的立场计算</a> </li>
            </ol>
        </div>
    </div>
    <div style="position:relative;" id="table">
    </div>

    <div id="checkInfo"></div>

</body>
</html>